﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace FUSE
{
    public class GameScene : DrawableGameComponent
    {
        ///<summary>
        /// List of child GameComponents
        /// </summary>
        private readonly List<GameComponent> components;

        /// <summary>
        /// Components of game scene
        /// </summary>
        public List<GameComponent> Components
        {
            get { return components; }
        }

        /// <summary>
        /// Constructor
        /// </summary>
        public GameScene(Game game)
            : base(game)
        {
            //Initialize the GameComponent list
            components = new List<GameComponent>();
            Visible = false;
            Enabled = false;
        }

        /// <summary>
        /// Show the scene
        /// </summary>
        public virtual void Show()
        {
            Visible = true;
            Enabled = true;
        }

        /// <summary>
        /// Hide the scene
        /// </summary>
        public virtual void Hide()
        {
            Visible = false;
            Enabled = false;
        }

        /// <summary>
        /// Allows the GameComponent to update itself properly:
        ///     if object in scene is disable (Enabled = false) then no Update
        /// </summary>
        public override void Update(GameTime gameTime)
        {
            // Update the child GameComponents if enabled
            for (int i = 0; i < components.Count; i++)
            {
                if (components[i].Enabled)
                {
                    components[i].Update(gameTime);
                }
            }
            base.Update(gameTime);
        }

        /// <summary>
        /// Allows the GameComponent to draw the content in the game screen.
        ///     call the Draw method for each components that is inserted into the List
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            // Draw the child GameComponents if drawable
            for (int i = 0; i < components.Count; i++)
            {
                GameComponent gc = components [i];
                if ((gc is DrawableGameComponent && ((DrawableGameComponent) gc).Visible))
                {
                    ((DrawableGameComponent) gc).Draw(gameTime);
                }
            }
            base.Draw(gameTime);
        }

    }
}
